package educar.controllers;

import educar.gui.AdministradorView;
import educar.gui.AlumnoView;
import educar.gui.DocenteView;
import educar.gui.IView;
import educar.gui.LoginView;
import educar.models.Session;
import educar.models.User;

public class LoginController implements IController {
	private LoginView view;

	public void process(String model){
		if(null!=view)
			if (User.authenticate(view.getUsername(), view.getPassword())){
				view.present("Bienvendo al sistema, " + Session.getCurrentUser().getUsername());
				view.resetCampos();
				view.esconder();
				
				if(Session.getCurrentUser().getRole().equals("administrador")) {
					AdministradorView vistaAdministrador=new AdministradorView();
					vistaAdministrador.setVisible(true);
;				}
				if(Session.getCurrentUser().getRole().equals("alumno")) {
					AlumnoView vistaAlumno=new AlumnoView();
					vistaAlumno.setVisible(true);
					
				}
				if(Session.getCurrentUser().getRole().equals("docente")) {
					DocenteView vistaADocente=new DocenteView();
					vistaADocente.setVisible(true);
				}
					
				
			} else {
				view.present("Nombre de usuario o password invalidos");
				view.resetCampos();
			}
	}

	@Override
	public void setView(IView view) {
		this.view = (LoginView) view;	
	}	
}
